textview: Set line height from css
authorMatthias Clasen <mclasen@redhat.com>
Sat, 7 Aug 2021 16:30:11 +0000 (12:30 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 22 Aug 2021 19:15:50 +0000 (15:15 -0400)
Set the line height in the default attributes from
the CSS style. This makes line height work in
GtkTextView.

gtk/gtktextattributes.h
gtk/gtktextlayout.c
gtk/gtktextview.c

index 5f539914d1ead4207f693b38bf1b6b726ded0112..3648dabf7c6cc2d23c6977ecd632cc759d53d3b6 100644 (file)
@@ -158,6 +158,7 @@ struct _GtkTextAttributes
   guint no_breaks : 1;
   guint show_spaces : 3; /* PangoShowFlags */
   guint no_hyphens : 1;
+  guint line_height_is_absolute : 1;
 };
 
 GtkTextAttributes* gtk_text_attributes_new         (void);
index 0e722dd3261fbea14b592b335e0e38490667ce91..a0cd16697d79a55145f186701c4ab69786b0c4a1 100644 (file)
@@ -1641,7 +1641,10 @@ add_text_attrs (GtkTextLayout      *layout,
 #if PANGO_VERSION_CHECK(1, 49, 0)
   if (style->line_height != 0.0)
     {
-      attr = pango_attr_line_height_new (style->line_height);
+      if (style->line_height_is_absolute)
+        attr = pango_attr_line_height_new_absolute (style->line_height * PANGO_SCALE);
+      else
+        attr = pango_attr_line_height_new (style->line_height);
       attr->start_index = start;
       attr->end_index = start + byte_count;
 
index 3f603f1bdcb1073bc02df2a3260c6b78406d7e82..46944bf82e7370ed1872388c76d5dbeb7949306e 100644 (file)
@@ -57,6 +57,7 @@
 #include "gtknative.h"
 #include "gtkwidgetprivate.h"
 #include "gtkjoinedmenuprivate.h"
+#include "gtkcsslineheightvalueprivate.h"
 
 /**
  * GtkTextView:
@@ -7640,6 +7641,7 @@ gtk_text_view_set_attributes_from_style (GtkTextView        *text_view,
   GtkCssStyle *style;
   const GdkRGBA black = { 0, };
   const GdkRGBA *color;
+  double height;
 
   if (!values->appearance.bg_rgba)
     values->appearance.bg_rgba = gdk_rgba_copy (&black);
@@ -7657,6 +7659,17 @@ gtk_text_view_set_attributes_from_style (GtkTextView        *text_view,
     pango_font_description_free (values->font);
 
   values->font = gtk_css_style_get_pango_font (style);
+
+  values->line_height = 0.0;
+  values->line_height_is_absolute = FALSE;
+
+  height = gtk_css_line_height_value_get (style->font->line_height);
+  if (height != 0.0)
+    {
+      values->line_height = height;
+      if (gtk_css_number_value_get_dimension (style->font->line_height) == GTK_CSS_DIMENSION_LENGTH)
+        values->line_height_is_absolute = TRUE;
+    }
 }
 
 static void